package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements Ioperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书.....");

        System.out.println("请输入你要图书的书名：");
        Scanner sc=new Scanner(System.in);
        String name= sc.nextLine();
        int currentsize= bookList.getUseSize();
        int pos=-1;
        int i=0;
        for(;i<currentsize;i++){
            Book book=bookList.getbook(i);
            if(book.getName().equals(name)){
               pos=i;
               break;
            }
        }
        if(i>=currentsize){
            System.out.println("没有找到书籍");
            return;
        }
        //开始删除
        for(int j=pos;j<currentsize-1;j++){
            Book book=bookList.getbook(j+1);
            bookList.setbook(j,book);
        }
        bookList.setUseSize(currentsize-1);
        bookList.setbook(currentsize-1,null);

    }
}
